﻿using System.Linq;
using System.Reflection;
using ProdUi.Attributes;

namespace ProdUi
{ 
  
    public class TestSession
    {
        public MethodInfo[] SessionMethods;
        public MethodInfo[] TestMethods;
        public MethodInfo[] TestSetups;
        public MethodInfo[] TestTeardowns;
        public string TestAssembly { get; set; }

       

public void ParseFile(string filename)
        {
            Assembly assembly = Assembly.LoadFile(filename);
            SessionMethods = assembly.GetTypes()
                .SelectMany(t => t.GetMethods())
                .Where(m => m.GetCustomAttributes(typeof (SessionSetupAttribute), false).Length > 0)
                .ToArray();
            TestMethods = assembly.GetTypes()
                .SelectMany(t => t.GetMethods())
                .Where(m => m.GetCustomAttributes(typeof (TestProdAttribute), false).Length > 0)
                .ToArray();
            TestSetups = assembly.GetTypes()
                .SelectMany(t => t.GetMethods())
                .Where(m => m.GetCustomAttributes(typeof (TestSetupAttribute), false).Length > 0)
                .ToArray();
            TestTeardowns = assembly.GetTypes()
                .SelectMany(t => t.GetMethods())
                .Where(m => m.GetCustomAttributes(typeof(TestTeardownAttribute), false).Length > 0)
                .ToArray();
        }

        public int Execute(object classobject, MethodInfo method)
        {
            method.Invoke(classobject, new object[] {});
            return 0;
        }
    }
}